package gateway.pojo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;


@Data
public class SS {
    private Metric metric ;
    private List<Object> value;

    @Override
    public String toString() {
        String name__ = metric.get__name__();
        StringBuilder sb = new StringBuilder(name__);
        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(this.metric,false,true);
        stringObjectMap.put("test","test");
        stringObjectMap.forEach((k,v)->{
            Object o = stringObjectMap.get(k);
            stringObjectMap.put(k,"\""+o+"\"");
        });

        sb.append(stringObjectMap);
        Object o = value.get(1);
        sb.append(" ").append(o);
        return sb.toString();
    }

    public static void main(String[] args) {
        String res = "{\"status\":\"success\",\"data\":{\"resultType\":\"vector\",\"result\":[{\"metric\":{\"Manufacturer\":\"pushgateway\",\"__name__\":\"batchjob1_user_counter\",\"exported_instance\":\"192.168.8.34\",\"exported_job\":\"batchjob1_user_counter\",\"idc\":\"fj\",\"instance\":\"10.211.55.20:9091\",\"job\":\"pushgateway\"},\"value\":[1715497302.211,\"197666\"]},{\"metric\":{\"Manufacturer\":\"pushgateway\",\"__name__\":\"batchjob1_user_counter\",\"exported_job\":\"batchjob1\",\"idc\":\"fj\",\"instance\":\"10.211.55.20:9091\",\"job\":\"pushgateway\"},\"value\":[1715497302.211,\"897666\"]}]}}";
        JsonRootBean<PrometheusResult> bean = JSONUtil.toBean(res, new TypeReference<JsonRootBean<PrometheusResult>>() {
        }, true);
        System.out.println(bean);
        if("success".equals(bean.getStatus())){
            PrometheusResult data = bean.getData();
            if(data!=null&& !CollectionUtils.isEmpty(data.getResult())){
                for (SS ss : data.getResult()) {
                    System.out.println(ss.toString());
                }
            }
        }
    }
}
